﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows;
using Microsoft.Practices.Prism.Modularity;
using Microsoft.Practices.Prism.Regions;
using Microsoft.Practices.Prism.UnityExtensions;
using Microsoft.Windows.Controls.Ribbon;
using PrismRibbonDemo;
using Sautom.ClientComunication.Services;
using Sautom.WpfClient.ViewModels;
using Sautom.WpfClient.Views;

namespace Sautom.WpfClient
{
    internal class Bootstrapper : UnityBootstrapper
    {
        public Bootstrapper()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("ru-RU");
            Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture("ru-RU");
        }

        protected override IModuleCatalog CreateModuleCatalog()
        {
            var catalog = Microsoft.Practices.Prism.Modularity.ModuleCatalog.CreateFromXaml(
                        new Uri("/Sautom.WpfClient;component/ModuleCatalog.xaml", UriKind.Relative));

            return catalog;
        }

        protected override DependencyObject CreateShell()
        {
            // Use the container to create an instance of the shell.
            MainWindow view = Container.TryResolve<MainWindow>();

            // Display the shell's root visual.
            view.Show();

            return view;
        }

        protected override RegionAdapterMappings ConfigureRegionAdapterMappings()
        {
            // Call base method
            var mappings = base.ConfigureRegionAdapterMappings();
            if (mappings == null) return null;

            // Add custom mappings
            mappings.RegisterMapping(typeof(Ribbon), Container.TryResolve<RibbonRegionAdapter>());

            // Set return value
            return mappings;
        }
    }
}
